﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace GEAR_Structure
{
    [Serializable]
    public class Category_material
    {
        private readonly int id;

        public int ID
        {
            get { return id; }
        }

        private List<Materiale> listmaterial;

        public List<Materiale> ListMaterial
        {
            get { return listmaterial; }
            set { listmaterial = value; }
        }
        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public Category_material(int _ID, List<Materiale> _materialList, string _description)
        {
            this.id = _ID;
            this.listmaterial = ListMaterial;
            this.description = _description;
        }

        public Category_material()
        {
            this.id = 0;
            this.listmaterial = new List<Materiale>();
            this.description = "";
        }

        /// <summary>
        /// Importa i dati da un nodo XML ben formattato(Vecchio energy design)
        /// </summary>
        /// <param name="node">Il nodo contenente i dati</param>
        /// <returns></returns>
        public static Category_material getByXML(XmlNode node)
        {
            Category_material cm = new Category_material();
            cm.description = node.SelectSingleNode("Description").InnerText;
            XmlNode listmaterial = node.SelectSingleNode("ListMaterial");
            foreach (XmlNode childmaterial in listmaterial.ChildNodes)
                cm.listmaterial.Add(Materiale.getByXML(childmaterial));
            return cm;
        }
    }
}
